Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented BibtexkeyChecker #2022

Merged
merged 6 commits into from
Sep 22, 2016
Merged

Implemented BibtexkeyChecker #2022

merged 6 commits into from
Sep 22, 2016

Conversation

grimes2
Copy link
Contributor

@grimes2 grimes2 commented Sep 20, 2016

Check for empty bibtexkey. #1779.

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@koppor
Copy link
Member

koppor commented Sep 21, 2016

Could add tests and a CHANGELOG entry? Maybe in a follow up, could you address #1779 (comment) so that the jumping to an entry works better. @bartsch-dev Maybe you have an idea for a quick implementation of that?

@grimes2
Copy link
Contributor Author

grimes2 commented Sep 21, 2016

Tests: It is difficult to test for an unexisting variable in this test environment. I'll test only for "assertCorrect".

@@ -112,6 +112,12 @@ public void testMonthChecks() {
}

@Test
public void testBibtexkeyChecks() {
assertCorrect(createContext("bibtexkey", "Knuth2014"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do one assertCorrect per Test please? 😇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we now have a class for each checker, we should also create a test class for each checker separately.
But I would think that is content for a new PR

Copy link
Contributor Author

@grimes2 grimes2 Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed my thumb up. A separate test class for every checker is too much (for evt. one or two entries). I think, it is better to organize the checker tests by fields (in methods) and not by checker classes.

@koppor
Copy link
Member

koppor commented Sep 21, 2016

Tests: I view the changes using the CodeCov plugin (see also https://github.com/JabRef/jabref/wiki/Tools) and this is the result:

grabbed_20160921-094240

I just wanted to ensure that everything is at least orange if not green 🎢

@grimes2
Copy link
Contributor Author

grimes2 commented Sep 21, 2016

I think, it is difficult to implement empty bibtexkey in a clean way. The problem is that the bibtexkey is not existing, but the constructor IntegrityMessage requires an existing entry and field. So this might be the reason, why codecov is complaining. A solution could be to overload the constructor IntegrityMessage for this special case.

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it looks good to me. Thanks for your contribution.
I just have a few remarks which should be implemented before we merge.


@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> valuekey = entry.getField(BibEntry.KEY_FIELD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use entry.getCiteKey.

Optional<String> valueyear = entry.getField(FieldName.YEAR);
String authortitleyear = entry.getAuthorTitleYear(100);

if (!valueauthor.isPresent() || !valuetitle.isPresent() || !valueyear.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this if statement. So if an entry is missing an author (or title/year) and also has no bibtexkey, then no warning will be printed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because getAuthorTitleYear(i) requires, that all three field exist. Otherwise some check tests are failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging based on the code, I think getAuthorTitleYear would return N/A: N/A (N/A) in the case where the fields are missing. I would suggest that you change the order of the if statements.
If the key is empty, then we definitely want to report a message. But if then all the author, title and year are empty, we use BibEntry.toString (it is a bit ugly) or otherwise we use getAuthorTitleYear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the order of the if statements causes the fail of all checker tests:
java.lang.AssertionError: expected:<[]> but was:<[[] in bibtexkey: empty bibtexkey: N/A: "N/A" (N/A)]

return Collections.emptyList();
}

if (!valuekey.isPresent()) {
Copy link
Member

@tobiasdiez tobiasdiez Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also check that the key is not empty (like in your second test below).
There is a similar convenient method in StringUtil already (I think it was called isNotBlank not sure if isBlank already exists but it should be easy to add).

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it looks good now!

@tobiasdiez tobiasdiez merged commit d512ebb into JabRef:master Sep 22, 2016
@grimes2 grimes2 deleted the emptybibtexkey branch September 25, 2016 08:38
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
* BibtexkeyChecker

* CHANGELOG.md and tests

* Changes 1

* checkstyle

* Change 2

* Change 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants